//封装
const host='http://xinzhi_school.jsyixin.com'

//axios封装post请求
function axiosPost(url,data,token) {
   let result = axios({
       method: 'POST',
       url: host+url,
       data: data,
       transformRequest:[function(data){
           let ret = '';
           for(let i in data){
               ret += encodeURIComponent(i)+'='+encodeURIComponent(data[i])+"&";
           }
           return ret;
       }],
	   // transformRequest: [function(data) {
	   //       data = JSON.stringify(data)
	   //       return data
	   //  }],
	   headers:{ 
		   'token':token,
	   }
   }).then(resp=> {
       return resp.data;
   }).catch(error=>{
       return "exception="+error;
   });
   return result;
}
function axiosGet(url,params) {
	let result = axios({
	    method: 'GET',
	    url: host+url,
	    params: params,
		headers:{
			'token':params
		}
	}).then(resp=> {
	    return resp.data;
	}).catch(error=>{
	    return "exception="+error;
	});
	return result;
}
function getQueryString(name) {
       var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
       var r = window.location.search.substr(1).match(reg);
       if(r != null) {
             return decodeURIComponent(r[2]);
       }
       return '';
}
// formdata 传数组
function formdataTypeFn(arr, name) {
	let obj = {}
	for(var i = 0; i<arr.length; i++) {
		let keys = name+'['+ i +']'
		obj[keys] = arr[i]
	}
	return obj
}
function formdataLyb(arr,arrtwo,keys,indexname,indexnametwo) {
	let obj = {}
	let obj_two = {}
	for(var i =0; i<arr.length; i++) {
		let keyy = keys+'['+ i +']'+'['+ indexname +']'
		let keyy_two = keys+'['+ i +']'+'['+ indexnametwo +']'
		obj[keyy] = arr[i]
		obj[keyy_two] = arrtwo[i]
	}
	let objs_data = {...obj,...obj_two};
	return objs_data
}
// axiosGet('/api/signUp', this.form).then(res => {
// 					  console.log(res)
// 				  })